// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   WebSelect.java

package com.vandagroup.common.util.web;

import java.util.Vector;

// Referenced classes of package com.vandagroup.common.util.web:
//            WebComponent, WebClauseComponent, WebOption

public class WebSelect extends WebComponent
    implements WebClauseComponent
{

    public String strSelectName;
    public Vector vOptions;

    public WebSelect(String paSelectName)
    {
        strSelectName = "SELECT";
        vOptions = new Vector();
        if(paSelectName != null)
            strSelectName = paSelectName;
    }

    public void addOption(String paValue, String paContent, boolean paRslt)
    {
        addOption(new WebOption(paValue, paContent, paRslt));
    }

    public void addOption(String paValue, String paContent)
    {
        addOption(new WebOption(paValue, paContent));
    }

    public void addOption(WebOption paOption)
    {
        vOptions.addElement(paOption);
    }

    public void setSelected(String paOptionValue, boolean paSelected)
    {
        for(int i = 0; i < vOptions.size(); i++)
        {
            WebOption w = (WebOption)vOptions.elementAt(i);
            String strWebOption = w.getValue();
            if(paSelected)
            {
                if(strWebOption.equalsIgnoreCase(paOptionValue))
                    w.setSelected(true);
                else
                    w.setSelected(false);
                continue;
            }
            if(!strWebOption.equalsIgnoreCase(paOptionValue))
                continue;
            w.setSelected(false);
            break;
        }

    }

    public void setValue(String paValue)
    {
        setSelected(paValue, true);
    }

    public String getValue()
    {
        for(int i = 0; i < vOptions.size(); i++)
        {
            WebOption w = (WebOption)vOptions.elementAt(i);
            if(w.isSelected())
                return w.getValue();
        }

        return null;
    }

    public String toString()
    {
        String strHtml = "<select name=\"" + strSelectName + "\">";
        for(int i = 0; i < vOptions.size(); i++)
        {
            WebOption vTmp = (WebOption)vOptions.elementAt(i);
            strHtml = strHtml + vTmp.toString();
        }

        strHtml = strHtml + "</select>";
        return strHtml;
    }
}
